package com.molichuxing.gateway.bff.car.convertor;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.date.DatePattern;
import com.alibaba.fastjson.JSONObject;
import com.molichuxing.gateway.bff.basic.entity.response.VehicleModlemakeVo;
import com.molichuxing.gateway.bff.car.entity.request.create.MaintenanceConfigCreateVo;
import com.molichuxing.gateway.bff.car.entity.request.modify.*;
import com.molichuxing.gateway.bff.car.entity.response.*;
import com.molichuxing.services.business.dto.request.create.MotRequestCreateDto;
import com.molichuxing.services.business.dto.response.*;
import com.molichuxing.services.infrastructure.dto.request.create.MaintenanceConfigCreateDto;
import com.molichuxing.services.infrastructure.dto.request.modify.*;
import com.molichuxing.services.infrastructure.dto.response.*;
import com.molichuxing.services.infrastructure.dto.response.CarDto;
import com.molichuxing.services.property.WarnConfigTypeEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.utils.DateUtil;
import com.molichuxing.gateway.bff.car.entity.request.create.AccidentExamineCreateVo;
import com.molichuxing.gateway.bff.car.entity.request.create.CarLicencePlateCreateVo;
import com.molichuxing.gateway.bff.car.entity.request.create.YearlyInspectionCreateVo;
import com.molichuxing.services.business.dto.request.create.AccidentExamineCreateDto;
import com.molichuxing.services.business.dto.request.create.CarLicencePlateCreateDto;
import com.molichuxing.services.business.dto.request.modify.CarCommercialInsuranceModifyDto;
import com.molichuxing.services.business.dto.request.modify.CarCompulsoryInsuranceModifyDto;
import com.molichuxing.services.business.dto.request.modify.CarInsuranceCommercialModifyDto;
import com.molichuxing.services.business.dto.request.modify.CarLicencePlateModifyDto;
import com.molichuxing.services.business.dto.request.modify.MaintenanceModifyDto;
import com.molichuxing.services.infrastructure.dto.request.create.YearlyInspectionCreateDto;
import com.molichuxing.services.property.CarCheckStatusEnum;
import com.molichuxing.services.property.CarInsuranceTypeEnum;
import com.molichuxing.services.property.MaintenanceStatusEnum;

public class Convert {

    //车辆检验
    public static CarCheckVo toCarCheckVo(CarCheckDto bean) {
        CarCheckVo beanDto = null;
        if (bean != null) {
            beanDto = new CarCheckVo();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    public static CarsFenceExceptionDetailVo toCarsFenceExceptionDetailVo(CarFenceExceptionBizDto bean) {
        CarsFenceExceptionDetailVo beanDto = null;
        if (bean != null) {
            beanDto = new CarsFenceExceptionDetailVo();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    //车辆检验图片LIST
    public static List<CarCheckVo> toCarCheckVoList(List<CarCheckDto> beanList) {
        List<CarCheckVo> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarCheckDto bean : beanList) {
                dtoList.add(toCarCheckVo(bean));
            }
        }
        return dtoList;
    }


    //车辆检验
    public static Paged<CarCheckVo> toPagedCarCheckVo(Paged<CarCheckDto> bean) {
        Paged<CarCheckVo> beanDto = null;
        if (bean != null) {
            beanDto = new Paged<CarCheckVo>();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setList(toCarCheckVoList(bean.getList()));
        }
        return beanDto;
    }


    //车辆检验信息
    public static CheckVo toCheckVo(CheckDto bean) {
        CheckVo beanDto = null;
        if (bean != null) {
            beanDto = new CheckVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setCarCheckInfo(bean.getCarCheckInfo());
        }
        return beanDto;
    }


    public static PdiCheckVo toPdiCheckVo(CheckDto bean, CheckDisputeDto checkDisputeDto) {
        PdiCheckVo beanDto = null;
        if (bean != null) {
            beanDto = new PdiCheckVo();
            BeanUtils.copyProperties(bean, beanDto);
        }
        if (checkDisputeDto != null) {
            if (bean.getStatus() == CarCheckStatusEnum.ALREADY_CHECK.getValue()) { //已检验
                beanDto.setIsUserApproves(true);
                beanDto.setIsUserApprovesStr("是");
            } else {
                beanDto.setIsUserApproves(checkDisputeDto.getIsUserApproves());
                beanDto.setIsUserApprovesStr((checkDisputeDto.getIsUserApproves() != null && checkDisputeDto.getIsUserApproves()) ? "是" : "否");
                if (!checkDisputeDto.getIsUserApproves()) {
                    beanDto.setReason(checkDisputeDto.getReason());
                }
            }
            beanDto.setDiscussLossFee(checkDisputeDto.getDiscussLossFee());
            beanDto.setDiscussremark(checkDisputeDto.getRemark());
            beanDto.setDiscussLossOpName(checkDisputeDto.getOpName()); //检验人
            beanDto.setDiscussLossCheckTime(checkDisputeDto.getCheckTime()); //检验时间
            if (checkDisputeDto.getIsUserApproves() || checkDisputeDto.getDiscussLossFee() == null) {
                beanDto.setHaveDiscussLoss(false);
            }
        } else {
            beanDto.setHaveDiscussLoss(false);
        }

        return beanDto;
    }

    //车辆检验图片LIST
    public static List<CheckImageVo> toCheckImageVoList(List<CheckImageDto> beanList) {
        List<CheckImageVo> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CheckImageDto bean : beanList) {
                dtoList.add(toCheckImageVo(bean));
            }
        }
        return dtoList;
    }

    public static CheckImageVo toCheckImageVoBean(List<CheckImageDto> beanList) {
        CheckImageVo dto = null;
        if (beanList != null && beanList.size() > 0) {
            dto = new CheckImageVo();
            Map<Integer, List<CheckImageDto>> imgMap = beanList.stream().collect(Collectors.groupingBy(CheckImageDto::getType));
            if (null != imgMap.get(1)) {
                dto.setAppearancePlan(imgMap.get(1).stream().map(e -> e.getDomainPath()).collect(Collectors.toList()));
            }
            if (null != imgMap.get(2)) {
                dto.setCheckPhoto(imgMap.get(2).stream().map(e -> e.getDomainPath()).collect(Collectors.toList()));
            }
            if (null != imgMap.get(3)) {
                dto.setPrePhoto(imgMap.get(3).stream().map(e -> e.getDomainPath()).collect(Collectors.toList()));
            }
            if (null != imgMap.get(4)) {
                dto.setPostPhoto(imgMap.get(4).stream().map(e -> e.getDomainPath()).collect(Collectors.toList()));
            }
            if (null != imgMap.get(5)) {
                dto.setUsedCheckPhoto(imgMap.get(5).stream().map(e -> e.getDomainPath()).collect(Collectors.toList()));
            }
        }
        return dto;
    }

    //车辆检验图片
    public static CheckImageVo toCheckImageVo(CheckImageDto bean) {
        CheckImageVo beanVo = null;
        if (bean != null) {
            beanVo = new CheckImageVo();
            BeanUtils.copyProperties(bean, beanVo);
        }
        return beanVo;
    }


    //车辆整备信息
    public static CheckPreparationVo toCheckPreparationVo(CheckPreparationDto bean) {
        CheckPreparationVo beanVo = null;
        if (bean != null) {
            beanVo = new CheckPreparationVo();
            BeanUtils.copyProperties(bean, beanVo);
        }
        return beanVo;
    }


    public static CheckModifyDto toCheckModifyDto(CheckModifyVo bean) {
        CheckModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new CheckModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    public static PdiCheckModifyDto toPdiCheckModifyDto(PdiCheckModifyVo bean) {
        PdiCheckModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new PdiCheckModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static DisPdiCheckModifyDto toDisPdiCheckModifyDto(DisPdiCheckModifyVo bean) {
        DisPdiCheckModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new DisPdiCheckModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    /********************************************车牌信息转换 开始 *****************************/
    public static CarLicencePlateDetailVo toCarLicencePlateDetailVo(CarLicencePlateDetailDto licencePlate, String vehicleName, String vehicleColorName, String companyName) {
        CarLicencePlateDetailVo beanVo = null;
        if (licencePlate != null) {
            beanVo = new CarLicencePlateDetailVo();
            BeanUtils.copyProperties(licencePlate, beanVo);
            beanVo.setVehicleName(vehicleName);
            beanVo.setVehicleColorName(vehicleColorName);
            beanVo.setSubCompanyName(companyName);
            if (null != licencePlate.getEndDate()) {
                beanVo.setEndDate(DateUtil.formatDate(licencePlate.getEndDate()));
            }
        }
        return beanVo;
    }

    public static CarLicencePlateCreateDto toCarLicencePlateDetailVo(CarLicencePlateCreateVo vo) {
        CarLicencePlateCreateDto beanVo = null;
        if (vo != null) {
            beanVo = new CarLicencePlateCreateDto();
            BeanUtils.copyProperties(vo, beanVo);
        }
        return beanVo;
    }

    public static CarLicencePlateModifyDto toCarLicencePlateModifyDto(CarLicencePlateModifyVo vo) {
        CarLicencePlateModifyDto beanVo = null;
        if (vo != null) {
            beanVo = new CarLicencePlateModifyDto();
            BeanUtils.copyProperties(vo, beanVo);
        }
        return beanVo;
    }


    /********************************************车牌信息转换 结束 *****************************/


    /********************************************年检信息转换 开始 *****************************/

    public static YearlyInspectionVo toYearlyInspectionVo(YearlyInspectionDto bean) {
        YearlyInspectionVo beanVo = null;
        if (bean != null) {
            beanVo = new YearlyInspectionVo();
            BeanUtils.copyProperties(bean, beanVo);
            beanVo.setEndDate(bean.getEndDate().toLocalDate());
        }
        return beanVo;
    }

    public static YearlyInspectionVo toYearlyInspectionVo(YearlyInspectionBizDto bean, String vehicleName, String stockName,
                                                          UserBizDto userBizDto, OwnershipDto ownershipDto) {
        YearlyInspectionVo beanVo = null;
        if (bean != null) {
            beanVo = new YearlyInspectionVo();
            BeanUtils.copyProperties(bean, beanVo);
            beanVo.setEndDate(bean.getEndDate().toLocalDate());
            beanVo.setVehicleName(vehicleName);
            beanVo.setStockName(stockName);
            if (ownershipDto != null) {
                beanVo.setOwnershipName(ownershipDto.getName());
            }

            if (userBizDto != null && StringUtils.isBlank(bean.getRecipients())) {
                beanVo.setRecipients(userBizDto.getRealName());
            }
            if (userBizDto != null && StringUtils.isBlank(bean.getRecipientsPhone())) {
                beanVo.setRecipientsPhone(userBizDto.getPhone());
            }
        }
        return beanVo;
    }

    public static YearlyInspectionCreateDto toYearlyInspectionCreateDto(YearlyInspectionCreateVo bean) {
        YearlyInspectionCreateDto beanVo = null;
        if (bean != null) {
            beanVo = new YearlyInspectionCreateDto();
            BeanUtils.copyProperties(bean, beanVo);
            if (StringUtils.isNotEmpty(bean.getEndDate())) {
                DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                beanVo.setEndDate(LocalDateTime.parse(bean.getEndDate(), df));
            }
        }
        return beanVo;
    }

    public static YearlyInspectionModifyDto toYearlyInspectionModifyDto(YearlyInspectionModifyVo bean) {
        YearlyInspectionModifyDto beanVo = null;
        if (bean != null) {
            beanVo = new YearlyInspectionModifyDto();
            BeanUtils.copyProperties(bean, beanVo);
            if (StringUtils.isNotEmpty(bean.getEndDate())) {
                LocalDate endDate = DateUtil.parseDate(bean.getEndDate());
                beanVo.setEndDate(DateUtil.getDayEnd(DateUtil.lastDayOfMonth(endDate)));
            }
        }
        return beanVo;
    }


    public static Paged<CarYearlyInspectVo> toCarYearlyInspectPage(Paged<CarYearlyInspectDto> page) {
        Paged<CarYearlyInspectVo> result = null;
        ;
        if (null != page) {
            result = new Paged<>();
            BeanUtils.copyProperties(page, result);
            result.setTab(page.getTab());
            result.setList(toCarYearlyInspectPage(page.getList()));
        }
        return result;
    }

    public static List<CarYearlyInspectVo> toCarYearlyInspectPage(List<CarYearlyInspectDto> beanList) {
        List<CarYearlyInspectVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarYearlyInspectDto bean : beanList) {
                dtoList.add(toGoodsVo(bean));
            }
        }
        return dtoList;
    }

    public static CarYearlyInspectVo toGoodsVo(CarYearlyInspectDto bean) {
        CarYearlyInspectVo beanDto = null;
        if (bean != null) {
            beanDto = new CarYearlyInspectVo();
            BeanUtils.copyProperties(bean, beanDto);
            DateTimeFormatter LOCAL_DATE = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            beanDto.setEndDate(bean.getEndDate().format(LOCAL_DATE));
        }
        return beanDto;
    }

    public static List<YearlyInspectionLogVo> toYearlyInspectionLogVo(List<YearlyInspectionLogBizDto> beanList) {
        List<YearlyInspectionLogVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (YearlyInspectionLogBizDto bean : beanList) {
                dtoList.add(toYearlyInspectionLogVo(bean));
            }
        }
        return dtoList;
    }

    public static YearlyInspectionLogVo toYearlyInspectionLogVo(YearlyInspectionLogBizDto bean) {
        YearlyInspectionLogVo beanDto = null;
        if (bean != null) {
            beanDto = new YearlyInspectionLogVo();
            BeanUtils.copyProperties(bean, beanDto);
            LocalDateTime completeDate = bean.getCompleteDate();
            LocalDateTime endDate = bean.getEndDate();
            if (completeDate != null) {
                beanDto.setCompleteDate(completeDate.toLocalDate());
            }
            if (endDate != null) {
                beanDto.setEndDate(endDate.toLocalDate());
            }
        }
        return beanDto;
    }

    public static MotRequestCreateDto toMotRequestCreateDto(YearlyInspectionModifyVo modifyVo, YearlyInspectionBizDto yearlyInspectionBizDto, OwnershipDto ownershipDto) {
        MotRequestCreateDto beanDto = null;
        if (modifyVo != null) {
            beanDto = new MotRequestCreateDto();
            BeanUtils.copyProperties(modifyVo, beanDto);
            beanDto.setLicencePlate(yearlyInspectionBizDto.getLicencePlate());
            beanDto.setVin(yearlyInspectionBizDto.getVin());
            beanDto.setInsureProveUrl(yearlyInspectionBizDto.getInsureProveUrl());
            beanDto.setOwnershipName(ownershipDto.getName());
        }
        return beanDto;
    }
    /********************************************年检信息转换 结束 *****************************/


    /********************************************保险信息转换 开始 *****************************/
    public static CarInsuranceDetailVo toCarInsuranceDetailVo(CarInsuranceDetailDto bean, String vehicleName, InsuranceCompanyDto insureCompany) {
        CarInsuranceDetailVo beanDto = null;
        if (bean != null) {
            beanDto = new CarInsuranceDetailVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setInsureTime(DateUtil.formatTime(bean.getInsureTime(), DatePattern.NORM_DATE_PATTERN));
            beanDto.setBeginTime(DateUtil.formatTime(bean.getBeginTime(), DatePattern.NORM_DATE_PATTERN));
            beanDto.setEndTime(DateUtil.formatTime(bean.getEndTime(), DatePattern.NORM_DATE_PATTERN));
            beanDto.setVehicleName(vehicleName);
            if (null != insureCompany) {
                beanDto.setInsuranceCompanyName(insureCompany.getName());
            }
        }
        return beanDto;
    }

    public static CarCompulsoryInsuranceModifyDto toCarCompulsoryInsuranceModifyDto(CarCompulsoryInsuranceModifyVo bean) {
        CarCompulsoryInsuranceModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new CarCompulsoryInsuranceModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setInsureTime(DateUtil.parseDateTime(bean.getInsureTime() + " 00:00:00"));
            beanDto.setBeginTime(DateUtil.parseDateTime(bean.getBeginTime() + " 00:00:00"));
            beanDto.setEndTime(DateUtil.parseDateTime(bean.getEndTime() + " 00:00:00"));
        }
        return beanDto;
    }


    public static CarCommercialInsuranceModifyDto toCarCommercialInsuranceModifyDto(CarCommercialInsuranceModifyVo bean) {
        CarCommercialInsuranceModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new CarCommercialInsuranceModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setCommercialList(toCarInsuranceCommercialModifyDto(bean.getCommercialList()));
        }
        return beanDto;
    }

    public static List<CarInsuranceCommercialModifyDto> toCarInsuranceCommercialModifyDto(List<CarInsuranceCommercialModifyVo> beanList) {
        List<CarInsuranceCommercialModifyDto> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarInsuranceCommercialModifyVo bean : beanList) {
                dtoList.add(toCarInsuranceCommercialModifyDto(bean));
            }
        }
        return dtoList;
    }

    public static CarInsuranceCommercialModifyDto toCarInsuranceCommercialModifyDto(CarInsuranceCommercialModifyVo bean) {
        CarInsuranceCommercialModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new CarInsuranceCommercialModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    public static Paged<CarInsuranceVo> toCarInsuranceVoPage(Paged<CarInsuranceDto> page) {
        Paged<CarInsuranceVo> result = null;
        ;
        if (null != page) {
            result = new Paged<>();
            BeanUtils.copyProperties(page, result);
            result.setList(toCarInsuranceVoPage(page.getList()));
        }
        return result;
    }

    public static List<CarInsuranceVo> toCarInsuranceVoPage(List<CarInsuranceDto> beanList) {
        List<CarInsuranceVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarInsuranceDto bean : beanList) {
                dtoList.add(toCarInsuranceVoPage(bean));
            }
        }
        return dtoList;
    }

    public static CarInsuranceVo toCarInsuranceVoPage(CarInsuranceDto bean) {
        CarInsuranceVo beanDto = null;
        if (bean != null) {
            beanDto = new CarInsuranceVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setBeginTime(DateUtil.formatDate(bean.getBeginTime()));
            beanDto.setEndTime(DateUtil.formatDate(bean.getEndTime()));
            beanDto.setInsureTime(DateUtil.formatDate(bean.getInsureTime()));
        }
        return beanDto;
    }

    public static InsuranceModifyDto toInsuranceModifyDto(InsuranceDto bean) {
        InsuranceModifyDto dto = null;
        if (bean != null) {
            dto = new InsuranceModifyDto();
            BeanUtils.copyProperties(bean, dto);
            dto.setInsuranceId(bean.getId());
        }
        return dto;
    }

    public static List<CarInsuranceVo> toCarInsuranceVo(List<CarInsuranceDto> beanDtos) {
        List<CarInsuranceVo> beanVos = null;
        if (beanDtos == null || beanDtos.isEmpty()) {
            return beanVos;
        }
        beanVos = new ArrayList<>(beanDtos.size());
        for (CarInsuranceDto beanDto : beanDtos) {
            if (beanDto.getType() == CarInsuranceTypeEnum.COMPULSORY_INSURANCE.getValue()) {
                // 交强险
                beanVos.add(toCarInsuranceVo(beanDto));
            } else if (beanDto.getType() == CarInsuranceTypeEnum.COMMERCIAL_INSURANCE.getValue()) {
                // 商业险
                beanVos.add(toCarInsuranceDetailVo((CarInsuranceDetailDto) beanDto));
            }
        }
        return beanVos;
    }

    public static CarInsuranceDetailVo toCarInsuranceDetailVo(CarInsuranceDetailDto beanDto) {
        CarInsuranceDetailVo beanVo = null;
        if (beanDto == null) {
            return beanVo;
        }
        beanVo = new CarInsuranceDetailVo();
        BeanUtils.copyProperties(beanDto, beanVo);
        beanVo.setBeginTime(DateUtil.formatDate(beanDto.getBeginTime()));
        beanVo.setEndTime(DateUtil.formatDate(beanDto.getEndTime()));
        beanVo.setInsureTime(DateUtil.formatDate(beanDto.getInsureTime()));
        beanVo.setCommercialList(toCarInsuranceCommercialVo(beanDto.getCommercialList()));

        return beanVo;
    }

    public static List<CarInsuranceCommercialVo> toCarInsuranceCommercialVo(
            List<CarInsuranceCommercialDto> beanDtos) {
        List<CarInsuranceCommercialVo> beanVos = null;
        if (beanDtos == null || beanDtos.isEmpty()) {
            return beanVos;
        }
        beanVos = new ArrayList<>(beanDtos.size());
        for (CarInsuranceCommercialDto beanDto : beanDtos) {
            beanVos.add(toCarInsuranceCommercialVo(beanDto));
        }

        return beanVos;
    }


    public static CarInsuranceCommercialVo toCarInsuranceCommercialVo(CarInsuranceCommercialDto beanDto) {
        CarInsuranceCommercialVo beanVo = null;
        if (beanDto == null) {
            return beanVo;
        }
        beanVo = new CarInsuranceCommercialVo();
        BeanUtils.copyProperties(beanDto, beanVo);

        return beanVo;
    }

    public static CarInsuranceVo toCarInsuranceVo(CarInsuranceDto beanDto) {
        CarInsuranceVo beanVo = null;
        if (beanDto == null) {
            return beanVo;
        }
        beanVo = new CarInsuranceVo();
        BeanUtils.copyProperties(beanDto, beanVo);
        beanVo.setBeginTime(DateUtil.formatDate(beanDto.getBeginTime()));
        beanVo.setEndTime(DateUtil.formatDate(beanDto.getEndTime()));
        beanVo.setInsureTime(DateUtil.formatDate(beanDto.getInsureTime()));

        return beanVo;
    }

    /******************************************** * 保险信息转换 结束 *****************************/


    /********************************************车辆信息转换 开始 *****************************/

    public static CarDetailVo toCarDetailVo(CarDetailBizDto bean) {
        CarDetailVo beanDto = null;
        if (bean != null) {
            beanDto = new CarDetailVo();
            BeanUtils.copyProperties(bean, beanDto);
            Map<String, String> imgMap = new HashMap<>();
            if (null != bean.getFactoryCertImg()) {
                imgMap.put("factoryCertImg", bean.getFactoryCertImg());
            }
            if (null != bean.getPurchaseInvoiceImg()) {
                imgMap.put("purchaseInvoiceImg", bean.getPurchaseInvoiceImg());
            }
            if (null != bean.getUniformityCertImg()) {
                imgMap.put("uniformityCertImg", bean.getUniformityCertImg());
            }

            if (null != bean.getRegisterCard()) {
                imgMap.put("registerCard", bean.getRegisterCard());
            }
            if (null != bean.getDrivingLicense()) {
                imgMap.put("drivingLicense", bean.getDrivingLicense());
            }
            if (null != bean.getTaxProof()) {
                imgMap.put("taxProof", bean.getTaxProof());
            }
            beanDto.setImgMap(imgMap);
        }
        return beanDto;
    }

    public static CarDetailModifyDto toCarDetailModifyDto(CarDetailModifyVo bean) {
        CarDetailModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new CarDetailModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    public static Paged<CarVo> toCarVoPage(Paged<CarDto> page, Map<Integer, String> vehicleMap, Map<Integer, VehicleColorDto> carDtoMap) {
        Paged<CarVo> result = null;
        ;
        if (null != page) {
            result = new Paged<>();
            BeanUtils.copyProperties(page, result);
            result.setList(toCarVoPage(page.getList(), vehicleMap, carDtoMap));
        }
        return result;
    }

    public static List<CarVo> toCarVoPage(List<CarDto> beanList, Map<Integer, String> vehicleMap, Map<Integer, VehicleColorDto> carDtoMap) {
        List<CarVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarDto bean : beanList) {
                dtoList.add(toCarVoPage(bean, vehicleMap, carDtoMap));
            }
        }
        return dtoList;
    }

    public static CarVo toCarVoPage(CarDto bean, Map<Integer, String> vehicleMap, Map<Integer, VehicleColorDto> carDtoMap) {
        CarVo beanDto = null;
        if (bean != null) {
            beanDto = new CarVo();
            BeanUtils.copyProperties(bean, beanDto);
            if ((null != vehicleMap) && (null != vehicleMap.get(bean.getVehicleId()))) {
                beanDto.setVehicleName(vehicleMap.get(bean.getVehicleId()));
            }
            if ((null != carDtoMap) && (null != carDtoMap.get(bean.getVehicleColorId()))) {
                beanDto.setVehicleColorName(carDtoMap.get(bean.getVehicleColorId()).getName());
            }
        }
        return beanDto;
    }

    public static List<CarVo> toCarVo(List<CarBizDto> beanList, Map<Integer, String> vehicleMap, Map<Integer, VehicleColorDto> carDtoMap) {
        List<CarVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarBizDto bean : beanList) {
                dtoList.add(toCarVo(bean, vehicleMap, carDtoMap));
            }
        }
        return dtoList;
    }

    public static CarVo toCarVo(CarBizDto bean, Map<Integer, String> vehicleMap, Map<Integer, VehicleColorDto> carDtoMap) {
        CarVo beanDto = null;
        if (bean != null) {
            beanDto = new CarVo();
            BeanUtils.copyProperties(bean, beanDto);
            if ((null != vehicleMap) && (null != vehicleMap.get(bean.getVehicleId()))) {
                beanDto.setVehicleName(vehicleMap.get(bean.getVehicleId()));
            }
            if ((null != carDtoMap) && (null != carDtoMap.get(bean.getVehicleColorId()))) {
                beanDto.setVehicleColorName(carDtoMap.get(bean.getVehicleColorId()).getName());
            }
        }
        return beanDto;
    }
    /********************************************车辆信息转换 结束 *****************************/


    /********************************************车辆事故信息转换 开始 *****************************/

    public static Paged<AccidentBizVo> toCarAccidentVoPage(Paged<AccidentBizDto> page, Map<Integer, UserBizDto> userMap, Map<String, String> vehicleMap) {
        Paged<AccidentBizVo> result = null;
        ;
        if (null != page) {
            result = new Paged<>();
            BeanUtils.copyProperties(page, result);
            result.setList(toCarAccidentVoPage(page.getList(), userMap, vehicleMap));
        }
        return result;
    }

    public static List<AccidentBizVo> toCarAccidentVoPage(List<AccidentBizDto> beanList, Map<Integer, UserBizDto> userMap, Map<String, String> vehicleMap) {
        List<AccidentBizVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (AccidentBizDto bean : beanList) {
                dtoList.add(toCarAccidentVoPage(bean, userMap, vehicleMap));
            }
        }
        return dtoList;
    }

    public static AccidentBizVo toCarAccidentVoPage(AccidentBizDto bean, Map<Integer, UserBizDto> userMap, Map<String, String> vehicleMap) {
        AccidentBizVo beanDto = null;
        if (bean != null) {
            beanDto = new AccidentBizVo();
            BeanUtils.copyProperties(bean, beanDto);
            if ((null != userMap) && (null != userMap.get(bean.getUserId()))) {
                beanDto.setUserName(userMap.get(bean.getUserId()).getName());
                beanDto.setRealName(userMap.get(bean.getUserId()).getRealName());
                beanDto.setUserPhone(userMap.get(bean.getUserId()).getPhone());
                beanDto.setIdNumber(userMap.get(bean.getUserId()).getIdNumber());
            }
            if ((null != vehicleMap) && (null != vehicleMap.get(bean.getVehicleId()))) {
                beanDto.setVehicleName(vehicleMap.get(bean.getVehicleId()));
            }
            if (null != bean.getVehicleId()) {
                beanDto.setVehicleId(Integer.parseInt(bean.getVehicleId()));
            }
        }
        return beanDto;
    }

    public static AccidentDetailVo toAccidentDetailVo(AccidentDetailDto bean) {
        AccidentDetailVo beanDto = null;
        if (bean != null) {
            beanDto = new AccidentDetailVo();
            BeanUtils.copyProperties(bean, beanDto);
            AccidentCarUserVo accidentCarUserVo = new AccidentCarUserVo();
            BeanUtils.copyProperties(bean.getAccidentCarUserDto(), accidentCarUserVo);
            beanDto.setAccidentCarUserVo(accidentCarUserVo);

            beanDto.setStatus(toAccidentStatusVo(bean.getStatus()));

            AccidentInfoVo accidentInfoVo = new AccidentInfoVo();
            BeanUtils.copyProperties(bean.getAccidentInfoDto(), accidentInfoVo);
            if (null != bean.getAccidentInfoDto().getAccidentTime()) {
                accidentInfoVo.setAccidentTime(DateUtil.formatTime(bean.getAccidentInfoDto().getAccidentTime()));
            }
            if (null != bean.getAccidentInfoDto().getReportTime()) {
                accidentInfoVo.setReportTime(DateUtil.formatTime(bean.getAccidentInfoDto().getReportTime()));
            }
            if (null != bean.getAccidentInfoDto().getCaseTime()) {
                accidentInfoVo.setCaseTime(DateUtil.formatTime(bean.getAccidentInfoDto().getCaseTime()));
            }
            if (null != bean.getAccidentInfoDto().getIsDie()) {
                accidentInfoVo.setIsDie(bean.getAccidentInfoDto().getIsDie());
            }
            if (null != bean.getAccidentInfoDto().getIsDieStr()) {
                accidentInfoVo.setIsDieStr(bean.getAccidentInfoDto().getIsDieStr());
            }
            beanDto.setAccidentInfoVo(accidentInfoVo);

            AccidentCommitVo commit = new AccidentCommitVo();
            BeanUtils.copyProperties(bean.getCommit(), commit);
            beanDto.setCommit(commit);
        }
        return beanDto;
    }

    public static AccidentExamineCreateDto toAccidentExamineCreateDto(AccidentExamineCreateVo bean) {
        AccidentExamineCreateDto beanDto = null;
        if (bean != null) {
            beanDto = new AccidentExamineCreateDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    public static List<AccidentStatusVo> toAccidentStatusVo(List<AccidentStatusDto> beanList) {
        List<AccidentStatusVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (AccidentStatusDto bean : beanList) {
                dtoList.add(toAccidentStatusVo(bean));
            }
        }
        return dtoList;
    }

    public static Map<Integer, AccidentStatusVo> toAccidentStatusVo(Map<Integer, AccidentStatusDto> map) {
        Map<Integer, AccidentStatusVo> result = null;
        if (map != null) {
            result = new HashMap<>();
            for (Integer key : map.keySet()) {
                result.put(key, toAccidentStatusVo(map.get(key)));
            }
        }
        return result;
    }


    public static AccidentStatusVo toAccidentStatusVo(AccidentStatusDto bean) {
        AccidentStatusVo beanDto = null;
        if (bean != null) {
            beanDto = new AccidentStatusVo();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    /********************************************车辆事故信息转换 开始 *****************************/


    /********************************************车辆违章信息转换 开始 *****************************/
    public static List<CarsViolationVo> toCarsViolationVo(List<CarsViolationDto> beanList, Map<Integer, UserBizDto> userMap) {
        List<CarsViolationVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarsViolationDto bean : beanList) {
                dtoList.add(toCarsViolationVo(bean, userMap));
            }
        }
        return dtoList;
    }

    public static CarsViolationVo toCarsViolationVo(CarsViolationDto bean, Map<Integer, UserBizDto> userMap) {
        CarsViolationVo beanDto = null;
        if (bean != null) {
            beanDto = new CarsViolationVo();
            BeanUtils.copyProperties(bean, beanDto);
            if ((null != userMap) && (null != userMap.get(bean.getUserId()))) {
                beanDto.setUserName(userMap.get(bean.getUserId()).getName());
                beanDto.setRealName(userMap.get(bean.getUserId()).getRealName());
                beanDto.setUserPhone(userMap.get(bean.getUserId()).getPhone());
                beanDto.setIdNumber(userMap.get(bean.getUserId()).getIdNumber());
            }
        }
        return beanDto;
    }

    /********************************************车辆违章信息转换 结束 *****************************/


    /********************************************车辆保养信息转换 开始 *****************************/
    public static Paged<MaintenanceBizVo> toMaintenanceBizVo(Paged<MaintenanceBizDto> beanDto) {
        Paged<MaintenanceBizVo> result = null;
        ;
        if (null != beanDto) {
            result = new Paged<>();
            BeanUtils.copyProperties(beanDto, result);
            result.setList(toMaintenanceBizVo(beanDto.getList()));
        }
        return result;
    }

    public static List<MaintenanceBizVo> toMaintenanceBizVo(List<MaintenanceBizDto> beanList) {
        List<MaintenanceBizVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (MaintenanceBizDto bean : beanList) {
                dtoList.add(toMaintenanceBizVo(bean));
            }
        }

        return dtoList;
    }

    public static MaintenanceBizVo toMaintenanceBizVo(MaintenanceBizDto bean) {
        MaintenanceBizVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceBizVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setPurchaseDate(bean.getPurchaseDate().toLocalDate());
            beanDto.setMaintainableDate(bean.getMaintainableDate().toLocalDate());
            beanDto.setOperationId(bean.getOperationId());
            beanDto.setOperationType(bean.getOperationType());
        }
        return beanDto;
    }


    public static List<MaintenanceRecordVo> toMaintenanceRecordVo(List<MaintenanceRecordBizDto> beanList) {
        List<MaintenanceRecordVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (MaintenanceRecordBizDto bean : beanList) {
                dtoList.add(toMaintenanceRecordVo(bean));
            }
        }

        return dtoList;
    }

    public static MaintenanceRecordVo toMaintenanceRecordVo(MaintenanceRecordBizDto bean) {
        MaintenanceRecordVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceRecordVo();
            BeanUtils.copyProperties(bean, beanDto);
            if (null != bean.getSettlementUrl()) {
                beanDto.setSettlementUrl(bean.getSettlementUrl());
            }
        }
        return beanDto;
    }

    public static MaintenanceRecordVo toMaintenanceRecordDto(MaintenanceLogDto bean) {
        MaintenanceRecordVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceRecordVo();
            BeanUtils.copyProperties(bean, beanDto);
            if (null != bean.getSettlementUrl()) {
                beanDto.setSettlementUrl(JSONObject.parseArray(bean.getSettlementUrl(), String.class));
            }
        }
        return beanDto;
    }

    public static MaintenanceDetailVo toMaintenanceDetailVo(MaintenanceDetailBizDto bean) {
        MaintenanceDetailVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceDetailVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setBasic(toMaintenanceBasicVo(bean.getBasic()));
            beanDto.setInfo(toMaintenanceInfoVo(bean.getInfo()));
            beanDto.setRecordList(toMaintenanceRecordVo(bean.getRecordList()));
        }
        return beanDto;
    }

    public static MaintenanceBasicVo toMaintenanceBasicVo(MaintenanceBasicBizDto bean) {
        MaintenanceBasicVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceBasicVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setPurchaseDate(bean.getPurchaseDate().toLocalDate());
            beanDto.setMaintainableDate(bean.getMaintainableDate().toLocalDate());
        }
        return beanDto;
    }

    public static MaintenanceInfoVo toMaintenanceInfoVo(MaintenanceInfoBizDto bean) {
        MaintenanceInfoVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceInfoVo();
            BeanUtils.copyProperties(bean, beanDto);
            if (null != bean.getSettlementUrl()) {
                beanDto.setSettlementUrl(bean.getSettlementUrl());
            }
        }
        return beanDto;
    }

    public static MaintenanceModifyDto toMaintenanceModifyDto(MaintenanceLogModifyVo bean, String checkName) {
        MaintenanceModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceModifyDto();
            if (0 == bean.getStatus()) {
                beanDto.setStatus(MaintenanceStatusEnum.AUDIT_PASS.getValue());
            } else {
                beanDto.setStatus(MaintenanceStatusEnum.AUDIT_REJECTED.getValue());
                beanDto.setRejectReason(bean.getRejectReason());
            }
            beanDto.setCheckDate(LocalDateTime.now());
            beanDto.setMaintenanceLogId(bean.getMaintenanceLogId());
            beanDto.setCheckName(checkName);
            beanDto.setOperateId(bean.getOperateId());
        }
        return beanDto;
    }


    public static List<IovTrajectoryVo> toIovTrajectoryVo(List<IovTrajectoryDto> beanList) {
        List<IovTrajectoryVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (IovTrajectoryDto bean : beanList) {
                dtoList.add(toIovTrajectoryVo(bean));
            }
        }
        return dtoList;
    }

    public static IovTrajectoryVo toIovTrajectoryVo(IovTrajectoryDto bean) {
        IovTrajectoryVo beanDto = null;
        if (bean != null) {
            beanDto = new IovTrajectoryVo();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    /********************************************车辆保养信息转换 结束 *****************************/


    public static Paged<CarsFenceExceptionVo> toCarFenceExceptionVoPage(Paged<CarFenceExceptionBizDto> page) {
        Paged<CarsFenceExceptionVo> result = null;
        ;
        if (null != page) {
            result = new Paged<>();
            BeanUtils.copyProperties(page, result);
            result.setList(toCarFenceExceptionVoPage(page.getList()));
        }
        return result;
    }

    public static List<CarsFenceExceptionVo> toCarFenceExceptionVoPage(List<CarFenceExceptionBizDto> beanList) {
        List<CarsFenceExceptionVo> dtoList = null;
        ;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (CarFenceExceptionBizDto bean : beanList) {
                dtoList.add(toCarFenceExceptionVoPage(bean));
            }
        }
        return dtoList;
    }

    public static CarsFenceExceptionVo toCarFenceExceptionVoPage(CarFenceExceptionBizDto bean) {
        CarsFenceExceptionVo beanDto = null;
        if (bean != null) {
            beanDto = new CarsFenceExceptionVo();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static List<WarnConfigVo> toWarnConfigVoList(List<WarnConfigDto> beanList, CarWarnConfigDto carOfflineConfig) {
        List<WarnConfigVo> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (WarnConfigDto bean : beanList) {
                dtoList.add(toWarnConfigVo(bean, carOfflineConfig));
            }
        }
        return dtoList;
    }

    public static WarnConfigVo toWarnConfigVo(WarnConfigDto bean, CarWarnConfigDto carOfflineConfig) {
        WarnConfigVo beanDto = null;
        if (bean != null) {
            beanDto = new WarnConfigVo();
            BeanUtils.copyProperties(bean, beanDto);
            Integer type = bean.getType();
            if (type != null && WarnConfigTypeEnum.CAR_OFFLINE.getValue() == type && carOfflineConfig != null) {
                bean.setWarnConfigId(carOfflineConfig.getId().intValue());
                bean.setValue(String.valueOf(carOfflineConfig.getParamValue()));
            }
        }
        return beanDto;
    }


    public static List<WarnConfigModifyDto> toWarnConfigModifyDtoList(List<WarnConfigModifyVo> beanList) {
        List<WarnConfigModifyDto> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (WarnConfigModifyVo bean : beanList) {
                dtoList.add(toWarnConfigModifyDto(bean));
            }
        }
        return dtoList;
    }

    public static WarnConfigModifyDto toWarnConfigModifyDto(WarnConfigModifyVo bean) {
        WarnConfigModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new WarnConfigModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static List<MaintenanceConfigVo> toMaintenanceConfigVoList(List<MaintenanceConfigDto> beanList, Map<Integer, String> vehicleMap) {
        List<MaintenanceConfigVo> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (MaintenanceConfigDto bean : beanList) {
                dtoList.add(toMaintenanceConfigVo(bean, vehicleMap));
            }
        }
        return dtoList;
    }

    public static MaintenanceConfigVo toMaintenanceConfigVo(MaintenanceConfigDto bean, Map<Integer, String> vehicleMap) {
        MaintenanceConfigVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceConfigVo();
            BeanUtils.copyProperties(bean, beanDto);
            if (vehicleMap != null && vehicleMap.size() > 0) {
                Integer vehicleId = bean.getVehicleId();
                String vehicleName = vehicleMap.get(vehicleId);
                beanDto.setVehicleName(vehicleName);
            }
        }
        return beanDto;
    }

    public static MaintenanceConfigVo toMaintenanceConfigVo(MaintenanceConfigDto bean, String vehicleName) {
        MaintenanceConfigVo beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceConfigVo();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setVehicleName(vehicleName);
        }
        return beanDto;
    }

    public static MaintenanceConfigCreateDto toMaintenanceConfigCreateDto(MaintenanceConfigCreateVo bean) {
        MaintenanceConfigCreateDto beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceConfigCreateDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static MaintenanceConfigModifyDto toMaintenanceConfigModifyDto(MaintenanceConfigModifyVo bean) {
        MaintenanceConfigModifyDto beanDto = null;
        if (bean != null) {
            beanDto = new MaintenanceConfigModifyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static List<VehicleModlemakeVo> toVehicleModlemakeVo(List<VehicleModlemakeBizDto> beanList) {
        List<VehicleModlemakeVo> dtoList = null;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (VehicleModlemakeBizDto bean : beanList) {
                dtoList.add(toVehicleModlemakeVo(bean));
            }
        }
        return dtoList;
    }

    public static VehicleModlemakeVo toVehicleModlemakeVo(VehicleModlemakeBizDto bean) {
        VehicleModlemakeVo beanDto = null;
        if (bean != null) {
            beanDto = new VehicleModlemakeVo();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

}
